<template>
  <a-upload :custom-request="uploadFile" :file-list="fileList" :multiple="false">
    <a-button type="primary">导入月工资表</a-button>
  </a-upload>
</template>
<script>
import request from "@/utils/request";
const uploadWageExcel = (data, params) => {
  return request({
    url: "/hr/api/v1/salaryBills/import",
    method: "post",
    headers: {
      "Content-Type": "multipart/form-data"
    },
    data,
    params: params
  });
};
export default {
  props: {
    companyId: {
      type: String,
      default: ""
    },
    month: {
      type: String,
      default: ""
    },
    year: {
      type: String,
      default: ""
    },
    tableName: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      fileList: []
    };
  },

  methods: {
    uploadFile(params) {
      const formData = new FormData();
      formData.append("file", params.file);
      uploadWageExcel(formData, {
        companyId: this.companyId,
        month: this.month,
        year: this.year,
        tableName: this.tableName
      })
        .then(res => {
          this.$message.success("导入成功");
          this.$emit("input", res.data);
          this.$emit("change", res.data);
          params.onSuccess(true);
        })
        .catch(err => {
          console.log("debug log --> ", err);
          params.onError(true);
        });
    }
  }
};
</script>
<style lang="scss"></style>
